From 487ca6de67c381a951b19a3ce09ace95a6f530d1 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 19 Nov 2015 14:36:38 -0800 Subject: [PATCH] Touch up a few last minor comments --- src/bin/rustc.rs | 3 ++- src/bin/rustdoc.rs | 5 +++-- src/cargo/lib.rs | 5 +---- src/cargo/util/config.rs | 24 ++++++++++++++++++------ src/cargo/util/rustc.rs | 4 ++-- tests/tests.rs | 2 +- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/bin/rustc.rs b/src/bin/rustc.rs index f157d9976..7eb86717e 100644 --- a/src/bin/rustc.rs +++ b/src/bin/rustc.rs @@ -67,7 +67,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); - let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); + let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, + config.cwd())); let opts = CompileOptions { config: config, diff --git a/src/bin/rustdoc.rs b/src/bin/rustdoc.rs index e62adc87f..5a33cb120 100644 --- a/src/bin/rustdoc.rs +++ b/src/bin/rustdoc.rs @@ -1,6 +1,6 @@ use cargo::ops; use cargo::util::{CliResult, Config}; -use cargo::util::important_paths::{find_root_manifest_for_cwd}; +use cargo::util::important_paths::{find_root_manifest_for_wd}; #[derive(RustcDecodable)] struct Options { @@ -65,7 +65,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); - let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path)); + let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, + config.cwd())); let mut doc_opts = ops::DocOptions { open_result: options.flag_open, diff --git a/src/cargo/lib.rs b/src/cargo/lib.rs index 1c85c686b..3688e958e 100644 --- a/src/cargo/lib.rs +++ b/src/cargo/lib.rs @@ -97,10 +97,7 @@ fn process(mut callback: F) { let mut config = None; let result = (|| { - let cwd = try!(env::current_dir().chain_error(|| { - human("couldn't get the current directory of the process") - })); - config = Some(try!(Config::new(shell(Verbose, Auto), cwd))); + config = Some(try!(Config::default())); let args: Vec<_> = try!(env::args_os().map(|s| { s.into_string().map_err(|s| { human(format!("invalid unicode in argument: {:?}", s)) diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index 8b2b09efc..4fe7c8ddd 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -11,6 +11,7 @@ use std::path::{Path, PathBuf}; use rustc_serialize::{Encodable,Encoder}; use toml; +use core::shell::{Verbosity, ColorConfig}; use core::{MultiShell, Package}; use util::{CargoResult, ChainError, Rustc, internal, human, paths}; @@ -31,12 +32,11 @@ pub struct Config { } impl Config { - pub fn new(shell: MultiShell, cwd: PathBuf) -> CargoResult { + pub fn new(shell: MultiShell, + cwd: PathBuf, + homedir: PathBuf) -> CargoResult { let mut cfg = Config { - home_path: try!(homedir(cwd.as_path()).chain_error(|| { - human("Cargo couldn't find your home directory. \ - This probably means that $HOME was not set.") - })), + home_path: homedir, shell: RefCell::new(shell), rustc_info: Rustc::blank(), cwd: cwd, @@ -54,6 +54,18 @@ impl Config { Ok(cfg) } + pub fn default() -> CargoResult { + let shell = ::shell(Verbosity::Verbose, ColorConfig::Auto); + let cwd = try!(env::current_dir().chain_error(|| { + human("couldn't get the current directory of the process") + })); + let homedir = try!(homedir(&cwd).chain_error(|| { + human("Cargo couldn't find your home directory. \ + This probably means that $HOME was not set.") + })); + Config::new(shell, cwd, homedir) + } + pub fn home(&self) -> &Path { &self.home_path } pub fn git_db_path(&self) -> PathBuf { @@ -227,7 +239,7 @@ impl Config { } fn scrape_rustc_version(&mut self) -> CargoResult<()> { - self.rustc_info = try!(Rustc::new(&self.rustc, self.cwd())); + self.rustc_info = try!(Rustc::new(&self.rustc)); Ok(()) } diff --git a/src/cargo/util/rustc.rs b/src/cargo/util/rustc.rs index 1ddc36db0..aedf6e19c 100644 --- a/src/cargo/util/rustc.rs +++ b/src/cargo/util/rustc.rs @@ -14,9 +14,9 @@ impl Rustc { /// /// If successful this function returns a description of the compiler along /// with a list of its capabilities. - pub fn new>(path: P, cwd: &Path) -> CargoResult { + pub fn new>(path: P) -> CargoResult { let mut cmd = util::process(path.as_ref()); - cmd.cwd(cwd).arg("-vV"); + cmd.arg("-vV"); let mut ret = Rustc::blank(); let mut first = cmd.clone(); diff --git a/tests/tests.rs b/tests/tests.rs index d79e1d2a0..19aaf0aff 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -65,7 +65,7 @@ mod test_cargo_verify_project; mod test_cargo_version; mod test_shell; -thread_local!(static RUSTC: Rustc = Rustc::new("rustc", &support::cwd()).unwrap()); +thread_local!(static RUSTC: Rustc = Rustc::new("rustc").unwrap()); fn rustc_host() -> String { RUSTC.with(|r| r.host.clone()) -- 2.30.2